<?php
namespace app\admin\validate;

use think\Validate;

class User extends Validate
{
    protected $rule =   [
        'username'  => ['require', 'max' => 10, 'min' => 2],
        'name'  => ['require', 'max' => 10, 'min' => 2],
        'email' => 'email',
        'phone' => ['regex' => '/^1[\w]{10}$/'],
        'password'   => ['require', 'max' => 12, 'min' => 6],
        'password_confirmation' => ['require', 'confirm:password']
    ];

    protected $message  =   [
        'name.require'     => '昵称必填',
        'name.max'         => '昵称最多不能超过10个字符',
        'name.min'         => '昵称不能少于2个字符',
        'username.require' => '用户名必填',
        'username.max'     => '用户名最多不能超过10个字符',
        'username.min'     => '用户名不能少于2个字符',
        'password.requireWith' => '密码必填',
        'password.require' => '密码必填',
        'password.max'     => '密码最多不能超过12个字符',
        'password.min'     => '密码不能少于6个字符',
        'password_confirmation.confirm' => '两次输入的密码不一致',
        'password_confirmation.requireWith' => '确认密码不能为空',
        'password_confirmation.require' => '确认密码不能为空',
        'email'            => '邮箱格式错误',
        'phone.regex'      => '手机号码格式错误',
    ];
    //场景 验证  （$result = $this->validate($data, 'app\admin\validate\User.edit');）
    //修改场景中 重新定义了 密码和确认密码规则。
    protected $scene = [
        'edit'  =>  ['username','name','email','phone'
            ,'password'=>[ 'max' => 12, 'min' => 6,'requireWith:password']
            , 'password_confirmation'=>['confirm:password','requireWith:password']
        ],
    ];

}
